
//获取应用实例
const app = getApp()
var commonData = require('../../data/data.js');
var commonController = require('../../data/commonControll.js');
Page({
  data: {
    nickName: "",
    userImg: "",
    catPrice: "",
    isShow: true,
    height: 600,
    maxSoure:0,
    version: -1
  },

  onLoad: function () {
    var that = this;
    this.setVersion();
    wx.getUserInfo({
      success: function (res) {
        that.setData({
          nickName: res.userInfo.nickName,
          userImg: res.userInfo.avatarUrl,
          catPrice: app.globalData.userInfo.CatPrice,
          maxSoure: app.globalData.userInfo.MaxSoure
        })
      }
    })
    this.getSystermMsg();
    setInterval(function(){
      that.setData({
     
        catPrice: app.globalData.userInfo.CatPrice
       
      })
    },3000)
  },
  setVersion: function () {
    var that = this;
    wx.request({
      url: app.appSetting.host + "weixin/GetVersion",
      data: {
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {

        that.setData({
          version: res.data.Result
        })

      }
    })
  },
  
  onShow: function () {
    wx.showShareMenu({
      //这里是为了分享群可以获取群信息，比如shareTickets
      withShareTicket: true
    })
  },
  gotoMonsters: function () {
    wx.navigateTo({
      url: 'monsterList',
    })
  },
  showVersionList: function () {
    wx.navigateTo({
      url: 'versionList',
    })
  },
  bindFormSubmit: function (e) {
    if (e.detail.value.textarea != '' && e.detail.value.textarea != null && e.detail.value.textarea != undefined && e.detail.value.textarea != "") {
      wx.showLoading({
        title: '提交中',
      })
      wx.request({
        url: app.appSetting.host + "Weixin/AddRemark?userId=" + app.globalData.userInfo.UserId,
        data: {
          Msg: e.detail.value.textarea,
        },
        method: 'POST',
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: function (res) {
          wx.hideLoading();
          if (res.data.Status == 0) {
            app.showMsg("提交成功");
          } else {
            app.showMsg(res.data.Message);
          }

        }
      })
    }
  },
  //获取屏幕高度，宽度
  getSystermMsg: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        commonData.screenInfo.height = res.windowHeight;
      }
    })
  },
  share:function(){
    wx.showShareMenu({
      withShareTicket: true
    })
  },
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '快来参与保卫猫园守护战',
      path: '/pages/index/index',
      success: function (res) {
        //getSystemInfo是为了获取当前设备信息，判断是android还是ios，如果是android
        //还需要调用wx.getShareInfo()，只有当成功回调才是转发群，ios就只需判断shareTickets
        wx.getSystemInfo({
          success: function (d) {
            console.log(d.platform);
            console.log(res.shareTickets);
            if (res.shareTickets == null) {
              wx.showToast({
                title: "分享到群有猫晶",
                duration: 2000
              });
              return;
            }
            if (d.platform == 'android' && (res.shareTickets.length > 0)) {
              wx.getShareInfo({
                shareTicket: res.shareTickets,
                success: function () {
                  console.log("安卓群");
                  app.sharePage();
                  wx.showToast({
                    title: "+1000猫晶",
                    duration: 2000
                  });
                },
                fail: function () {
                  console.log("安卓好友");
                  wx.showToast({
                    title: "分享到群有猫晶",
                    duration: 2000
                  });
                }
              })
              return;
            }
            if (d.platform == 'ios' && (res.shareTickets.length > 0)) {

              console.log("IOS群");
              app.sharePage();
              wx.showToast({
                title: "+1000猫晶",
                duration: 2000
              });
            } else {
              console.log("IOS好友");
              wx.showToast({
                title: "分享到群里才分享到群有猫晶能获得猫晶",
                duration: 2000
              });
            }
          },
          fail: function (res) {
            wx.showToast({
              title: "转发失败",
              duration: 2000
            });
          }
        })
      },
      fail: function (res) {
        // 转发失败
        console.log("取消转发");
      }
    }
  }
})
